package com.yunshu.yunshuapp;

import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * TODO: document your custom view class.
 */
public class NavigationBar extends RelativeLayout {

    private String title;
    private Toolbar toolbar;

    public NavigationBar(Context context) {
        super(context);
        init(context,null, 0);
    }

    public NavigationBar(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context,attrs, 0);
    }

    public NavigationBar(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context,attrs, defStyle);
    }

    private void init(Context context,AttributeSet attrs, int defStyle) {
        if (isInEditMode()) {
            this.setBackgroundColor(0x00D1C0);
            return;
        }

        View.inflate(context, R.layout.sample_navigation_bar, this);

        toolbar = (Toolbar)findViewById(R.id.toolbar);
        toolbar.setTitle("");
    }


    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
        TextView titileTV = (TextView) findViewById(R.id.titleTV);
        titileTV.setText(title);
    }

    public void putInActivity(final  AppCompatActivity activity){
        toolbar.setTitle("");
        activity.setSupportActionBar(toolbar);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                activity.onBackPressed();
            }
        });
    }

    public void setOnMenuItemClickListener(Toolbar.OnMenuItemClickListener listener) {
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setOnMenuItemClickListener(listener);
    }
}
